package cn.mw.cmdb.entity;

import cn.mw.cmdb.service.ServiceChoose;
import cn.mw.cmdb.service.impl.AlgorithmInfoServiceImpl;
import cn.mw.cmdb.util.DataCreateInfo;
import cn.mw.components.mongodb.anno.AutoId;
import cn.mw.components.mongodb.anno.CMDBProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Document("mw_cmdbmd_algorithm")
public class AlgorithmInfo implements ServiceChoose, DataCreateInfo {

    // ID字段
    @CMDBProperty(searchType = PropertyTypeString.ID, searchPrefix = "_")
    @AutoId
    @Schema(description = "id")
    private String id;

    @CMDBProperty(searchType = PropertyTypeString.ID, keywordSearch = true)
    // 名称 CMDB 这里使用国际化会失效
    private String algorithmName;

    // 类型字段，可选值为'繁忙度[busyness] 可用性[availability] 健康度[healthiness]'
    @CMDBProperty(searchType = PropertyTypeString.ID, keywordSearch = true)
    @Schema(description = "繁忙度[busyness] 可用性[availability] 健康度[healthiness]")
    @NotBlank(message = "类型不能为空")
    private String type;

    // 计算指标字段: 繁忙度\可用性\健康度 计算指标
    @CMDBProperty
    @Schema(description = "计算指标字段")
    private Map<String, Object> dataMetric;

    // 计算周期字段，表示计算周期的整数值
    @CMDBProperty
    @Schema(description = "计算周期字段，表示计算周期的整数值")
    private Integer calculationPeriod;

    // 计算周期单位字段，表示计算周期的单位
    @CMDBProperty
    @Schema(description = "计算周期单位字段，表示计算周期的单位")
    private String calculationPeriodUnit;

    // 计算区间数组字段，由开始时间和结束时间组成
    @CMDBProperty
    @Schema(description = "计算区间数组字段，由开始时间和结束时间组成")
    private List<CalculationIntervalTime> calculationInterval;

    // 计算方式字段，根据用户填写的信息生成
    @CMDBProperty(searchType = PropertyTypeString.ID, keywordSearch = true)
    @Schema(description = "计算方式字段，根据用户填写的信息生成")
    private String calculationMethod;

    // 应用范围字段，可选值为'全局[global] 自定义[custom]'
    @CMDBProperty(searchType = PropertyTypeString.ID, keywordSearch = true)
    @Schema(description = "全局[global] 自定义[custom]")
    private String applicationScope;

    // 模型ID数组字段，如果应用范围选择自定义，传递模型ID或模型组ID
    @CMDBProperty()
    @Schema(description = "模型ID数组,模型组字段，如果应用范围选择自定义，传递模型ID或模型组ID")
    private List<List<String>> modelGroupOrIdList;

    @CMDBProperty()
    @Schema(description = "模型ID数组, 存储转换的模型ID, 前端无需理会")
    private List<String> modelIdList;

    @CMDBProperty
    @Schema(description = "cron表达式")
    private String cronExpression;

    @CMDBProperty
    @Schema(description = "powerJob 任务的ID")
    private List<Long> jobIds;

    @CMDBProperty(searchType = PropertyTypeString.ID)
    @Schema(description = "创建人")
    protected Long creater;

    @CMDBProperty(searchType = PropertyTypeTime.ID)
    @Schema(description = "创建时间")
    protected Date createTime;

    @CMDBProperty(searchType = PropertyTypeString.ID)
    @Schema(description = "修改人")
    protected Long modifier;

    @CMDBProperty(searchType = PropertyTypeTime.ID)
    @Schema(description = "修改时间")
    protected Date modificationTime;

    @Override
    public String getServiceId() {
        return AlgorithmInfoServiceImpl.ID;
    }

    @Data
    public static class CalculationIntervalTime {
        private List<String> range;
    }
}
